package com.yanqu.road.server.cmd.activity.springdinner;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SpringDinnerProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.springdinner.SpringDinnerModule;
import com.yanqu.road.server.manger.activity.springdinner.SpringDinnerMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_SPRINGDINNER_SHARE, desc = "分享")
public class SpringDinnerShareCmd extends AbstractCommand {

    private int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        SpringDinnerProto.SpringDinnerShareReqMsg reqMsg = SpringDinnerProto.SpringDinnerShareReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(SpringDinnerMgr.getShowTimeActivityId() == 0 || SpringDinnerMgr.getShowTimeActivityId() != activityId){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }

        ret = player.getModule(SpringDinnerModule.class).share();

    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            SpringDinnerProto.SpringDinnerShareRespMsg.Builder respMsg = SpringDinnerProto.SpringDinnerShareRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_SPRINGDINNER_SHARE, respMsg);
        }
    }
}
